package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.method.Method;
import com.azier.kapacitor.script.method.Quite;
import com.azier.kapacitor.script.node.nodebind.FromNodeBind;
import com.azier.kapacitor.script.node.nodebind.StatsNodeBind;
import com.azier.kapacitor.util.CollectionUtil;

import java.util.ArrayList;

/**
 * 1 * @Author: luoj
 * 2 * @Date: 2019/11/8 11:27
 * 3
 */
public class StreamNode extends AbstractNode implements FromNodeBind, StatsNodeBind {
    private static final String name = "stream";

    public StreamNode() {
        super(null,new ArrayList<>(),"");
        this.headNode = this;
    }

    public static StreamNode stream(){
        return new StreamNode();
    }

    public StreamNode quite(){
        Quite quite = new Quite();
        super.addMethod(quite);
        return this;
    }

    @Override
    public StringBuilder append(StringBuilder stringBuilder) {
        stringBuilder.append(name);
        if (CollectionUtil.isNotEmpty(methods)) {
            for (Method method : methods) {
                method.append(stringBuilder);
            }
        }
        if(nextNode!=null){
            nextNode.append(stringBuilder);
        }
        return stringBuilder;
    }



}
